import 'package:flutter/material.dart';

///
/// Navigator API : https://api.flutter-io.cn/flutter/widgets/Navigator-class.html
/// `Navigator` 有好几个同名的类，我们这里的是 flutter 中的 class
///
///
class DemoNavigator extends StatelessWidget {
  const DemoNavigator({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: '导航页面',
      home: MyNavigator01(),
    );
  }
}

// New Buttons and Button Themes : https://flutter.cn/docs/release/breaking-changes/buttons
// button 样式
final ButtonStyle raisedButtonStyle = ElevatedButton.styleFrom(
  onPrimary: Colors.black87,
  primary: Colors.grey[300],
  minimumSize: const Size(88, 36),
  padding: const EdgeInsets.symmetric(horizontal: 16),
  shape: const RoundedRectangleBorder(
    borderRadius: BorderRadius.all(Radius.circular(2)),
  ),
);

class MyNavigator01 extends StatelessWidget {
  const MyNavigator01({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('导航页面'),),
      body: Center(
        // New Buttons and Button Themes : https://flutter.cn/docs/release/breaking-changes/buttons
        // RaisedButton -> ElevatedButton
        child: ElevatedButton(
          style: raisedButtonStyle,
          onPressed: (){
            Navigator.push(context,
                MaterialPageRoute(builder: (context) => const SecondScreen()));
          },
          child: const Text('查看商品详情页'),
        ),
      ),
    );
  }
}

///
/// 第二个页面，点击 button 后将要去往的页面
///
class SecondScreen extends StatelessWidget {
  const SecondScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '商品详情页',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('商品详情页'),
        ),
        body: Center(child: ElevatedButton(
          style: raisedButtonStyle,
          onPressed: () {
            Navigator.pop(context);
          },
          child: const Text('返回'),
        )),
      ),
    );
  }
}
